package cn.hbu.zlfw.patent.dao.impl;


import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import cn.hbu.zlfw.common.base.dao.impl.BaseDaoImpl;
import cn.hbu.zlfw.common.util.Utility;
import cn.hbu.zlfw.patent.dao.PatentSynergyDao;
import cn.hbu.zlfw.patent.entity.PatentSynergy;
/**
 * 
 * @ClassName: PatentSynergyDaoImpl 
 * @Description: 专利协同申请书dao接口实现
 * @author 王鹏伟<1223443289@qq.com>
 * @date 2017年11月3日 上午10:53:45  
 * @version V1.0
 */
@Repository("patentSynergyDao")
public class PatentSynergyDaoImpl extends BaseDaoImpl<PatentSynergy, String> implements PatentSynergyDao{
	/*
	 * (non-Javadoc)
	 * @see cn.hbu.zlfw.patent.dao.PatentSynergyDao#getNewestSynergyByPatentId(java.lang.String)
	 */
	@Override
	public PatentSynergy getNewestSynergyByPatentId(String patentId) {
		String hql = "from PatentSynergy ps where ps.patent.id=:patentId order by ps.createTime desc";
		List<PatentSynergy> patentSynergies = this.getSession().createQuery(hql)
				.setParameter("patentId", patentId).list();
		return patentSynergies.get(0);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.hbu.zlfw.patent.dao.PatentSynergyDao#getPatentSynergyByParams(java.util.Map)
	 */
	@Override
	public PatentSynergy getPatentSynergyByParams(Map<String, Object> params) {
		StringBuffer sbfhql = new StringBuffer();
		sbfhql.append("from PatentSynergy ps where ");
		for (Entry<String, Object> entry : params.entrySet()) {
			sbfhql.append(entry.getKey()+"=:"+entry.getKey()+"and ");
		}
		Query query=this.getSession().createQuery(sbfhql.substring(0,sbfhql.length()-4));
		return (PatentSynergy) Utility.queryParameterUtil(query, params).uniqueResult();
	}

}
